﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.Base;

namespace ERP_RORZE_PRODUCT.Product.Quotation
{
    public partial class ctrlQuotationMaterial : DevExpress.XtraEditors.XtraUserControl
    {
        ClsQuationDAO clsQuationDAO = new ClsQuationDAO();
        DataTable dt;
        QMaterial b = new QMaterial();

        public ctrlQuotationMaterial()
        {
            InitializeComponent();
        }

        void Reload(object sender, EventArgs e)
        {
            dt = clsQuationDAO.GetAllQuotationMaterial();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
        }
        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            b.RecordNo = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "RecordNo").ToString());
            clsQuationDAO.DeleteQuotationMaterial(b);
            Reload(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frm_QMaterialAdd frmAdd = new frm_QMaterialAdd();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.ShowDialog();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                frm_QMaterialEdit frmEdit = new frm_QMaterialEdit();
                frmEdit.Length = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Length").ToString();
                frmEdit.MaterialID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaterialID").ToString();
                frmEdit.MaterialPrice = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaterialPrice").ToString();
                frmEdit.MaterialType = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaterialType").ToString();
                frmEdit.MPartNo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MPartNo").ToString();
                frmEdit.Note = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Note").ToString();
                frmEdit.Price = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Price").ToString();
                frmEdit.QuotationID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "QuotationID").ToString();
                frmEdit.RecordNo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "RecordNo").ToString();
                frmEdit.Shape = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Shape").ToString();
                frmEdit.Thickness = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Thickness").ToString();
                frmEdit.Width = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Width").ToString();
                frmEdit.Reload += new EventHandler(Reload);
                frmEdit.ShowDialog();
            }
            catch
            {
            }
        }

        private void ctrlQuotationMaterial_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            btnAdd_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            btnDelete_Click(sender, e);
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            clsConstantsFuction.ExportToExcel(gridView1, 1, true);
        }
    }
}
